package com.ruoyi.web.controller.app;



import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.nongjt.domain.Certificate;
import com.ruoyi.nongjt.service.ICertificateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 合格证Controller(小程序)
 * 
 * @author ruoyi
 * @date 2024-09-27
 */
@RestController
@RequestMapping("/app/certificate")
public class AppCertificateController extends BaseController
{
    @Autowired
    private ICertificateService certificateService;

    /**
     * 查询合格证列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Certificate certificate)
    {
        startPage();
        List<Certificate> list = certificateService.selectCertificateList(certificate);
        return getDataTable(list);
    }

    /**
     * 获取合格证详细信息
     */
    @GetMapping(value = "/{certificateId}")
    public AjaxResult getInfo(@PathVariable("certificateId") Long certificateId)
    {
        return success(certificateService.selectCertificateByCertificateId(certificateId));
    }

    /**
     * 新增合格证
     */
    @Log(title = "合格证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Certificate certificate)
    {
        return toAjax(certificateService.insertCertificate(certificate));
    }

    /**
     * 修改合格证
     */
    @Log(title = "合格证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Certificate certificate)
    {
        return toAjax(certificateService.updateCertificate(certificate));
    }

    /**
     * 删除合格证
     */
    @Log(title = "合格证", businessType = BusinessType.DELETE)
    @DeleteMapping("/{certificateIds}")
    public AjaxResult remove(@PathVariable Long[] certificateIds)
    {
        return toAjax(certificateService.deleteCertificateByCertificateIds(certificateIds));
    }
}